package com.mzy.linear_struct.代码随想录.贪心;

/**
 * @Author: mizy3
 * @Date: 2024/08/15/上午12:50
 * @Description:
 */
public class Pro55跳跃游戏 {
    /*public boolean canJump(int[] nums) {


        int cover = nums[0] + 0;
        for (int i = 1; i <= cover; i++) {
            cover = Math.max(i + nums[i], cover);
            if(cover >= nums.length - 1) return true;

        }
        return false;
    }*/

    public static void main(String[] args) {
        new Pro55跳跃游戏().canJump(new int[]{3, 2, 1, 0, 4});
    }

    private boolean canJump(int[] nums) {
        int cover = nums[0];
        for (int i = 1; i <= cover; i++) {
            cover = Math.max(i + nums[i], cover);
            if (cover >= nums.length - 1) {
                return true;
            }
        }
        return false;
    }

/*    private boolean canJump(int[] nums) {
        int cover = nums[0];
        for (int i = 1; i <= cover; i++) {
            cover = Math.max(nums[i] + i, cover);
            if(cover >= nums.length - 1) return true;
        }
        return false;
    }*/
}
























